<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>商品管理</title>
	<meta name="decorator" content="default"/>
	<style type="text/css">
		.imgsty{
			width:250px;
			height:250px;
		}
	</style>
	<%
		Object optObj = request.getAttribute("opt");
		String opt = null;
		if(optObj!=null){
			opt = (String)optObj;
		}
		if(opt!=null && opt.equals("detail")){ 
	%>
	 <script type="text/javascript">
		$(document).ready(function() {
			$(this).find("input").each(function() {
				$(this).attr("disabled", "disabled");
				}); 
			$(this).find("select").each(function() {
				$(this).attr("disabled", "disabled");
				});
		});
	</script>
	 <%
	 	}else{
	 %>
	<script type="text/javascript">
		$(document).ready(function() {
			//$("#name").focus();
			$("#inputForm").validate({
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
		});
	</script>
	<%}%>
	<script type="text/javascript">
		function ajaxFileUpload(ipt,imgStr) {
		    //图片格式验证
		    var x = ipt;
		    if (!x || !x.value) return;
		    var patn = /\.jpg$|\.jpeg$|\.png$|\.gif$/i;
		    if (!patn.test(x.value)) {
		        alert("您选择的似乎不是图像文件。");
		        x.value = "";
		        return;
		    }

		    var elementIds = [ipt]; //flag为id、name属性名
		    var hiddenIpt = ipt.previousElementSibling;
		    $.ajaxFileUpload({
		        url: '${ctx}/pic/img/upload', 
		        type: 'post',
		        secureuri: false, //一般设置为false
		        fileElementId: ipt.id, // 上传文件的id、name属性名
		        dataType: 'json', //返回值类型，一般设置为json、application/json
		        elementIds: elementIds, //传递参数到服务器
		        success: function (data, status) {
		            if (data.status != 200) {
		                alert("文件太大，请上传不大于5M的文件！");
		                return;
		            }else {
		                //这里为上传并做一下请求显示处理，返回的data是对应上传的文件名
		            	document.getElementById(imgStr).src = data.data
		            	hiddenIpt.value = data.data
		            }
		        },
		        error: function (data, status, e) {
		            alert(e);
		        }
		    });
		    //return false;
		}
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/goods/bizGoods">商品列表</a></li>
		<li class="active"><a href="${ctx}/goods/bizGoods/form?id=${bizGoods.id}">商品<shiro:hasPermission name="goods:bizGoods:edit">${not empty bizGoods.id?'修改':'添加'}</shiro:hasPermission><shiro:lacksPermission name="goods:bizGoods:edit">查看</shiro:lacksPermission></a></li>
	</ul><br/>
	<form:form id="inputForm" modelAttribute="bizGoods" action="${ctx}/goods/bizGoods/save" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<sys:message content="${message}"/>		
		<div class="control-group">
			<label class="control-label">商品标题：</label>
			<div class="controls">
				<form:input path="goodTitle" htmlEscape="false" maxlength="11" class="input-xlarge  required"/>
					<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">商品头图：</label>
			<div class="controls">
				<img id="goodShowPic" alt="商品头图" class="imgsty" src="${not empty bizGoods.goodPic?bizGoods.goodPic:'/static/img/timg.jpg'}" /><br/>
				<form:hidden path="goodPic" class="input-middle required" />
				<input type="file" name="goodPicImg" id="goodPicImg" onchange="ajaxFileUpload(this,'goodShowPic')" class="input-middle"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">商品描述图：</label>
			<div class="controls">
				<img id="goodPicsShow" alt="商品描述图" class="imgsty" src="${not empty bizGoods.goodPics?bizGoods.goodPics:'/static/img/timg.jpg'}" /><br/>
				<form:hidden path="goodPics" class="input-middle required"/>
				<input type="file" name="goodPicsImg" id="goodPicsImg" onchange="ajaxFileUpload(this,'goodPicsShow')" class="input-middle "/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">售价积分：</label>
			<div class="controls">
				<form:input path="priceJifen" htmlEscape="false" maxlength="11" class="input-xlarge  required"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">售卖方式：</label>
			<div class="controls">
				<form:select path="sellType" class="input-xlarge required">
					<form:option value="" label=""/>
					<form:options items="${fns:getDictList('sell_type')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
				</form:select>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		
		<div class="control-group">
			<label class="control-label">商品状态：</label>
			<div class="controls">
				${fns:getDictLabel(bizGoods.goodStatus, 'goodsStatus', '')}
			</div>
		</div>
		
		<div class="control-group">
			<label class="control-label">商品类型：</label>
			<div class="controls">
				<form:select path="goodType" class="input-xlarge required">
					<form:option value="" label=""/>
					<form:options items="${fns:getDictList('goodType')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
				</form:select>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">开始时间：</label>
			<div class="controls">
				<input name="startTime" type="text" readonly="readonly" maxlength="20" class="input-medium required Wdate "
					value="<fmt:formatDate value="${bizGoods.startTime}" pattern="yyyy-MM-dd HH:mm:ss"/>"
					onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',isShowClear:false});"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">结束时间：</label>
			<div class="controls">
				<input name="endTime" type="text" readonly="readonly" maxlength="20" class="input-medium required Wdate "
					value="<fmt:formatDate value="${bizGoods.endTime}" pattern="yyyy-MM-dd HH:mm:ss"/>"
					onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',isShowClear:false});"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">商品类别：</label>
			<div class="controls">
				<sys:treeselect id="baseCategory" name="goodCategoryId" value="${bizGoods.goodCategoryId}" labelName="bizGoods.goodCategoryName" labelValue="${bizGoods.goodCategoryName}"
					title="分类" url="/category/baseCategory/treeData?categoryTypeVal=3"   cssClass="required" allowClear="true"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">库存数：</label>
			<div class="controls">
				<form:input path="stockNum" htmlEscape="false" maxlength="11" class="input-xlarge "/>
			</div>
			<span class="help-inline"><font color="red">*</font> </span>
		</div>
		<div class="control-group">
			<label class="control-label">商品描述：</label>
			<div class="controls">
				<form:textarea id="content" htmlEscape="true" path="goodDesc" rows="4" maxlength="200" class="input-xxlarge"/>
				<sys:ckeditor replace="content" uploadPath="/cms/article" />
			</div>
		</div>
		<div class="form-actions">
			<shiro:hasPermission name="goods:bizGoods:edit"><input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/>&nbsp;</shiro:hasPermission>
			<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
		</div>
	</form:form>
</body>
</html>